package org.example.day11;

import java.util.concurrent.locks.ReentrantLock;

/**
 *  4.1.12.3 lock.isLocked()  判断此锁是否被任意线程所占有
 **/
public class MyThread14 {
    private ReentrantLock lock;
    public MyThread14(boolean isFair){
        lock = new ReentrantLock(isFair);
    }
    public void serviceMethod(){
        try {
            System.out.println(lock.isLocked());
            lock.lock();
            System.out.println(lock.isLocked());
        } finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        final MyThread14 m14 = new MyThread14(true);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                m14.serviceMethod();
            }
        };
        Thread thread = new Thread(runnable);
        thread.start();
    }
}
